package com.typhoon.dao;

import com.typhoon.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/10/15 下午8:05
 * @description
 * @modified by
 * @since V2.0.0
 */
@Repository
@Slf4j
public class UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public List<User> listAll() {
        List<User> list = this.jdbcTemplate.query("select * from User", BeanPropertyRowMapper.newInstance(User.class));
        if(null == list || list.isEmpty()) {
            return Collections.emptyList();
        }
        log.info("UserDao.listAll find list size={}",list.size());
        return list;
    }


}
